package cn.smbms.controller;

import java.util.HashMap;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.smbms.pojo.User;
import cn.smbms.service.Collect.CollectService;
import cn.smbms.tools.Constants;

import com.alibaba.fastjson.JSONArray;

@Controller
@RequestMapping("/Collect")
public class CollectController {
	@Resource
	private CollectService collectService;

	// 添加收藏
	@RequestMapping(value = "/Collectadd", method = RequestMethod.POST)
	@ResponseBody
	public Object Order(HttpSession session, @RequestParam String proid) {
		int i = collectService.add(
				((User) session.getAttribute(Constants.USER_SESSION)).getId(),
				Integer.parseInt(proid));
		HashMap<String, String> resultMap = new HashMap<String, String>();

		if (i > 0) {
			resultMap.put("res", "true");

		} else {
			resultMap.put("res", "false");
		}
		return JSONArray.toJSONString(resultMap);

	}

	// 删除收藏
	@RequestMapping(value = "/CollectRemo", method = RequestMethod.POST)
	@ResponseBody
	public Object CollectRemo(HttpSession session, @RequestParam String proid) {
		int i = collectService.del(
				((User) session.getAttribute(Constants.USER_SESSION)).getId(),
				Integer.parseInt(proid));
		HashMap<String, String> resultMap = new HashMap<String, String>();

		if (i > 0) {
			resultMap.put("res", "true");

		} else {
			resultMap.put("res", "false");
		}
		return JSONArray.toJSONString(resultMap);

	}

}
